package a07_二叉树;

/**
 * <p>
 * a06_翻转二叉树复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/1/13
 */
public class a06_翻转二叉树复习2 {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return root;
        }
        reverse(root);
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

    private void reverse(TreeNode node){
        TreeNode temp = node.left;
        node.left = node.right;
        node.right = temp;
    }
}
